/**
 * 
 */
package com.qiyou.dao.proxy;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.qiyou.dao.IFriendDao;
import com.qiyou.dao.impl.FriendDaoImpl;
import com.qiyou.db.IDatabase;
import com.qiyou.entity.Friend;
import com.qiyou.entity.UserInfo;
import com.qiyou.util.DBUtil;

/**
 * 好友数据操作代理
 * 
 * @author 赛艳志
 * 
 */
public class FriendDaoProxy implements IFriendDao {
    private Connection conn = null;
    private IFriendDao dao = null;

    public FriendDaoProxy(IDatabase database) {
        this.conn = database.getConnection();
        this.dao = new FriendDaoImpl(conn);
    }

    @Override
    public boolean doCreate(Friend friend) throws SQLException {
        if (null != friend) {
            try {
                return dao.doCreate(friend);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return false;
    }

    @Override
    public boolean doDelete(String userID, String friendID) throws SQLException {
        if ((null != userID) && (null != friendID)) {
            try {
                return dao.doDelete(userID, friendID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return false;
    }

    @Override
    public List<UserInfo> getFriends(String userID) throws SQLException {
        if (null != userID) {
            try {
                return dao.getFriends(userID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return null;
    }

}
